<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Create a special or ordinary file (POSIX.1)</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.posix-mkfifo.html">« posix_mkfifo</a></li>
      <li style="float: right;"><a href="function.posix-setegid.html">posix_setegid »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.posix.html">POSIX 函数</a></li>
    <li>Create a special or ordinary file (POSIX.1)</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.posix-mknod" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">posix_mknod</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">posix_mknod</span> &mdash; <span class="dc-title">
   Create a special or ordinary file (POSIX.1)
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.posix-mknod-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>posix_mknod</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$major</code><span class="initializer"> = 0</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$minor</code><span class="initializer"> = 0</span></span><br>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Creates a special or ordinary file.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.posix-mknod-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">filename</code></dt>

     <dd>

      <p class="para">
       The file to create
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">flags</code></dt>

     <dd>

      <p class="para">
       This parameter is constructed by a bitwise OR between file type (one of
       the following constants: <strong><code>POSIX_S_IFREG</code></strong>,
       <strong><code>POSIX_S_IFCHR</code></strong>, <strong><code>POSIX_S_IFBLK</code></strong>,
       <strong><code>POSIX_S_IFIFO</code></strong> or
       <strong><code>POSIX_S_IFSOCK</code></strong>) and permissions.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">major</code></dt>

     <dd>

      <p class="para">
       The major device kernel identifier (required to pass when using
       <strong><code>S_IFCHR</code></strong> or <strong><code>S_IFBLK</code></strong>).
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">minor</code></dt>

     <dd>

      <p class="para">
       The minor device kernel identifier.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.posix-mknod-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.posix-mknod-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3299">
    <p><strong>示例 #1 A <span class="function"><strong>posix_mknod()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$file&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'/tmp/tmpfile'</span><span style="color: #007700">;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;file&nbsp;name<br /></span><span style="color: #0000BB">$type&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">POSIX_S_IFBLK</span><span style="color: #007700">;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;file&nbsp;type<br /></span><span style="color: #0000BB">$permissions&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0777</span><span style="color: #007700">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;octal<br /></span><span style="color: #0000BB">$major&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$minor&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">8</span><span style="color: #007700">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;/dev/random<br /><br /></span><span style="color: #007700">if&nbsp;(!</span><span style="color: #0000BB">posix_mknod</span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$type&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">$permissions</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$major</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$minor</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">'Error&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">posix_get_last_error</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">':&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">posix_strerror</span><span style="color: #007700">(</span><span style="color: #0000BB">posix_get_last_error</span><span style="color: #007700">()));<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.posix-mknod-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.posix-mkfifo.html" class="function" rel="rdfs-seeAlso">posix_mkfifo()</a> - Create a fifo special file (a named pipe)</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>